package com.gomoku;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class ViewRecordsFrame extends JFrame {
    public ViewRecordsFrame() {
        setTitle("查看游戏记录");
        setSize(600, 400);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLocationRelativeTo(null);
        setResizable(false);

        JList<String> recordList = new JList<>();
        recordList.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        JScrollPane scrollPane = new JScrollPane(recordList);

        JButton backButton = new JButton("返回");
        backButton.addActionListener(e -> {
            dispose();
            new ReplayMenu().setVisible(true);
        });

        JButton refreshButton = new JButton("刷新列表");
        refreshButton.addActionListener(e -> loadRecords(recordList));

        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        buttonPanel.add(refreshButton);
        buttonPanel.add(backButton);

        add(scrollPane, BorderLayout.CENTER);
        add(buttonPanel, BorderLayout.SOUTH);

        loadRecords(recordList);
    }

    private void loadRecords(JList<String> recordList) {
        // 在实际应用中，这里应该从文件系统加载游戏记录
        DefaultListModel<String> model = new DefaultListModel<>();
        model.addElement("示例记录1 (2023-01-01)");
        model.addElement("示例记录2 (2023-01-02)");
        model.addElement("示例记录3 (2023-01-03)");
        recordList.setModel(model);
    }
}